<!--
 * @Author: 极客James
 * @Motto: 求知若渴,虚心若愚
 * @Github: https://github.com/Geek-James/ddBuy
 * @掘金: https://juejin.im/user/5c4ebc72e51d4511dc7306ce
 * @LastEditTime: 2019-11-07 09:18:59
 * @Description: 我的->我的订单->订单类型
 * @FilePath: /ddBuy/src/views/mine/Children/MyOrderChildren/OrderType.vue
 -->
<template>
  <div id="orderType">
    <div  class="noDataPlaceHold">
      <!-- <img src="./../../../../images/mine/noData.jpeg"
           alt=""> -->
      <!-- <span class="desc">{{$t('mine.feedbackTip')}}</span> -->
      <el-table
        :data="tableData"
        stripe
        style="width: 100%">
        
        <el-table-column
          prop="orderInfoWaybillNum"
          label="订单号">
        </el-table-column>

        <el-table-column
          prop="orderInfoTime"
          label="创建时间">
            <template slot-scope="scope">
              {{ scope.row.orderInfoTime.substr(0,10) }}
            </template>
        </el-table-column>

        <el-table-column
          prop="orderInfoSalePrice"
          label="支付金额">
            <template slot-scope="scope">
              {{ scope.row.orderInfoSalePrice | moneyFormat }}
            </template>
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
           <el-button v-if="scope.row.orderInfoState==0"
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">去支付</el-button>
          <el-button v-if="scope.row.orderInfoState==20"
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">确认收货</el-button>
          <el-button v-if="scope.row.orderInfoState==30"
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">去评价</el-button>
        <el-button v-if="scope.row.orderInfoState==0"
          size="mini"
          @click="handleDelete(scope.$index, scope.row)">取消订单</el-button>
        <el-button v-if="scope.row.orderInfoState==10"
          size="mini"
          @click="handleDelete(scope.$index, scope.row)">退款</el-button>
        <el-button v-if="scope.row.orderInfoState==20"
          size="mini"
          @click="handleDelete(scope.$index, scope.row)">退款</el-button>
        <el-button v-if="scope.row.orderInfoState==40"
          size="mini"
          @click="handleDelete(scope.$index, scope.row)">删除订单</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script type="text/javascript">
import { Col } from 'vant'
export default {
  props: {
    orderTypeDataArray: Array
  },
  mounted () {
    this.GetList()
  },
  data () {
    return {
      tableData: [],
      inventories:[],
      listQuery: {
        page: 1,
        limit: 5,
        skipCount: 0,
        maxResultCount: 100,
        importance: undefined,
        title: undefined,
        orderInfoState: -1,
        orderInfoWaybillNum: undefined,
        sort: '+id'
      },
    }
  },
  components: {

  },
  methods: {
    GetList(){
      if(this.orderTypeDataArray[0]==1)
      {
        this.listQuery.orderInfoState=0
      }

      if(this.orderTypeDataArray[0]==2)
      {
        this.listQuery.orderInfoState=10
      }

      if(this.orderTypeDataArray[0]==3)
      {
        this.listQuery.orderInfoState=20
      }

      this.axios.get('https://localhost:44341/api/app/order/order-info-list-dto',{params:this.listQuery})
      .then(r=>{
        this.tableData=r.data.items
      })
    },
    handleEdit(index,row){
      window.open('https://localhost:44341/api/app/a-li-pay/pay?Subject='
      +row.orderInfoWaybillNum+'&outTradeNo='+row.orderInfoId+'&totalAmount='+row.orderInfoPayPrice+'&returnUrl='+'','_blank')

    },
    handleDelete(index,row){
      console.log(row.getOrderAttachedDto)
      //获取购买数量和产品主键
      for (let inde = 0; inde <row.getOrderAttachedDto.length; inde++) {
        console.log(row.getOrderAttachedDto[index].productId)
          let poduct={
            inven: 1, //执行减库存
            productid: row.getOrderAttachedDto[inde].productId, //产品主键
            productSum: row.getOrderAttachedDto[inde].productSum//购买数量
          }
        this.inventories.push(poduct)
      }

      this.axios.delete('https://localhost:44341/api/app/order/order-delete',{params:{orderInfoWaybillNum:row.orderInfoWaybillNum}})
          .then(x=>{
            if(x.data>0){
               this.axios.put('https://localhost:44341/api/app/manual-prouct/inventory',this.inventories)
               this.$message('取消成功')
               this.$router.push('/dashboard/mine/myOrder')
            }
            else{
               this.$message.error('取消');
            }
          })
    }
  }
}
</script>

<style lang="less" scoped>
#orderType {
  margin-top: 5rem;
  height: 20rem;
  .noDataPlaceHold {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    img {
      width: 60%;
      height: 60%;
    }
    .desc {
      color: grey;
      font-size: 0.6rem;
    }
  }
  .noData {
    margin-top: 3rem;
    width: 100%;
    height: 100%;
    text-align: center;
  }
}
</style>